package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.VegetationImage;
import com.fsnbigdata.domain.QVegetationImage;
import com.fsnbigdata.domain.Vegetation;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = VegetationImageRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = VegetationImageRepositoryCustom.class)
@Transactional(readOnly = true)
public class VegetationImageRepositoryImpl extends QueryDslRepositorySupportExt<VegetationImage> implements VegetationImageRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    VegetationImageRepositoryImpl() {
        super(VegetationImage.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LOCATION = "location";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CODE = "code";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CREATE_DATE = "createDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DESCRIPTION = "description";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String AUTHOR = "author";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String URL = "url";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String VEGETATION = "vegetation";

    /**
     * TODO Auto-generated method documentation
     *
     * @param vegetation
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<VegetationImage> findByVegetation(Vegetation vegetation, GlobalSearch globalSearch, Pageable pageable) {
        QVegetationImage vegetationImage = QVegetationImage.vegetationImage;
        JPQLQuery<VegetationImage> query = from(vegetationImage);
        Assert.notNull(vegetation, "vegetation is required");
        query.where(vegetationImage.vegetation.eq(vegetation));
        Path<?>[] paths = new Path<?>[] { vegetationImage.vegetation, vegetationImage.code, vegetationImage.description, vegetationImage.location, vegetationImage.author, vegetationImage.url, vegetationImage.createDate };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(VEGETATION, vegetationImage.vegetation).map(CODE, vegetationImage.code).map(DESCRIPTION, vegetationImage.description).map(LOCATION, vegetationImage.location).map(AUTHOR, vegetationImage.author).map(URL, vegetationImage.url).map(CREATE_DATE, vegetationImage.createDate);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, vegetationImage);
    }
}
